/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.fasepa.sgpf.dao;

import br.gov.fasepa.sgpf.entity.ContratoServidor;
import br.gov.fasepa.sgpf.factoryDAO.GenericDAO;
import java.util.List;
import javax.persistence.Query;

/**
 *
 * @author marcosdj
 */
public class ContratoSevidorDAO extends GenericDAO<ContratoServidor> {

    public ContratoServidor obter(String matricula) {
        ContratoServidor contratoServidor = new ContratoServidor();
        String query = "ContratoServidor.findByMatricula";
        final Query q = getEntityManager().createNamedQuery(query).
                setParameter("matricula", matricula);
        try {
            return (ContratoServidor) q.getSingleResult();
        } catch (Exception e) {
            return null;
        }
    }

    public List<ContratoServidor> ListarAtivos() {
        String query = "SELECT c FROM ContratoServidor c WHERE c.status != 'inativo' ORDER BY c.servidor.nome ";
        final Query q = getEntityManager().createQuery(query);
        try {
            return (List<ContratoServidor>) q.getResultList();
        } catch (Exception e) {
            return null;
        }
    }
}
